/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using OpenServers.Net.Common.FileSystem;
using OpenServers.Net.Common.FileSystem.Disk;
using OpenServers.Net.Common.FileSystem.Virtual;
using OpenServers.Net.Common.Listener;
using OpenServers.Net.Common.Security;
using OpenServers.Net.Common.Socket;
using OpenServers.Net.Common.State;

namespace OpenServers.Net.Common {
    public class Examples {
        public void NonsecureTcpListener1() {
            new NonsecureTcpListener(21);
        }

        public void DiskFileSystem1() {
            new DiskFileSystem(@"c:\temp");
        }

        public void DiskFileSystem2() {
            DiskFileSystem dfs = new DiskFileSystem(@"c:\temp");
            IFile file = dfs.GetFile("dir1/a.txt");
        }

        public void VirtualFileSystem1() {
            VirtualDirectory root = new VirtualDirectory(null, null);
            root.ReadOnly = true;

            VirtualDirectory dir1 = new VirtualDirectory(root, "dir1");
            VirtualFile file1 = new VirtualFile(dir1, "a.txt");
            dir1.GetItems().Add(file1);

            VirtualDirectory dir2 = new VirtualDirectory(root, "dir2");

            VirtualDirectory dir3 = new VirtualDirectory(root, "dir3");

            VirtualFileSystem fileSystem = new VirtualFileSystem(root);
        }

        public void OpenSecurityProvider1() {
            new OpenSecurityProvider();
        }

        public void NtAuthSecurityProvider() {
            new NtAuthSecurityProvider();
        }

        public class Server1 {
            public class MyState : AbstractState {
                public MyState(IListener listener, ISocket clientSocket)
                    : base(listener, clientSocket) {
                }
            }

            public class MyServer : AbstractServer {
                public MyServer() {
                    InitializeState += MyInitializeState;
                }

                public override IState CreateState(IListener listener, ISocket clientSocket) {
                    return new MyState(listener, clientSocket);
                }

                public void MyInitializeState(IServer server, IState stateArg) {
                    MyState state = (MyState)stateArg;
                    state.DataReceived += DataReceived;
                }

                private void DataReceived(IState state, byte[] buffer, int received) {
                    // process data and send responses.
                }
            }
        }
    }
}